//
//  LYCHTTPClient.swift
//  新浪微博
//
//  Created by liuyanchi on 16/7/30.
//  Copyright © 2016年 liuyanchi. All rights reserved.
//

import UIKit
import AFNetworking

// MARK:-- 定义一个枚举值
enum LYCHTTPClientType:String{

    case GET = "GET"
    case POST = "POST"

}

class LYCHTTPClient: AFHTTPSessionManager {
    
    // MARK:--swift单例
    static let shareInstance: LYCHTTPClient = {
    
    let afn = LYCHTTPClient()
    
    // 设置网络请求的文本类型text/plain
    afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        return afn
    
    }()
    
    // 自己封装一个GET和POST的方法,降低其他类与GET和POST的耦合度
    func request(type:LYCHTTPClientType, URLString: String, parameters: AnyObject?, progress: ((NSProgress) -> Void)?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?){
    
        if type == .GET {
            
      self.GET(URLString, parameters: parameters, progress: progress, success: success, failure: failure)
    
        }else  if type == .POST {
//        
       self.POST(URLString, parameters: parameters, progress: progress, success: success, failure: failure)
        
        
        }
    
    }
    
}
